package com.wenhai.spring.bean.definition;

import com.wenhai.xiaomage.spring.ioc.overview.dependency.domain.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author:wenhai
 * @Description: 实例化Bean
 * @Date:2020/3/24
 */
public class BeanInstantiationDemo {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext cxt = new ClassPathXmlApplicationContext("/META-INF/bean-instantiation-context.xml");
        cxt.refresh();
        User userByStaticMethod = cxt.getBean("user-by-static-method", User.class);
        User userByInstanceMethod = cxt.getBean("user-by-instance-method", User.class);
        User userByInstanceMethod2 = cxt.getBean("user-by-instance-method", User.class);
//        User userByFactoryBean = cxt.getBean("user-by-factory-bean", User.class);
        Object factoryBean = cxt.getBean("&user-by-factory-bean");
//        User userByFactoryBean = cxt.getBean("user-by-factory-bean", User.class);
        System.out.println("userByStaticMethod:" + userByStaticMethod);
        System.out.println("userByInstanceMethod:" + userByInstanceMethod);
//        System.out.println("userByFactoryBean:" + userByFactoryBean);
        System.out.println("factoryBean:" + factoryBean);
        System.out.println(userByStaticMethod == userByInstanceMethod);
        cxt.close();
    }
}
